rm(list = setdiff(ls(), lsf.str()))
# Data processing ----------------------------------------------------------
all_content <- readLines("Study 2/Study2_data.csv")

#process data
skip_second <- all_content[-2]
# took skip_second away here, but still not working properly.
data <- read.csv(textConnection(all_content), header=TRUE, stringsAsFactors = FALSE)
#create unieqe respondent ID 
data$id <- sample(1210, size = nrow(data))
id <- c(data$id, data$id)

# Create data.trump.RData ------------------------------------
#complete conjoint (1) or not (0)------
data$conjoint <- ifelse(data$Popchoice=="",0,1) 

#Trump favorability: rating from very unfavorable to very favorable
data$Trumpfav <-NA
data$Trumpfav[data$polfavorability_1==1]=4
data$Trumpfav[data$polfavorability_1==2]=3
data$Trumpfav[data$polfavorability_1==3]=2
data$Trumpfav[data$polfavorability_1==4]=1

#Clinton favorability: rating from very unfavorable to very favorable
data$Clintonfav <-NA
data$Clintonfav[data$polfavorability_2==1]=4
data$Clintonfav[data$polfavorability_2==2]=3
data$Clintonfav[data$polfavorability_2==3]=2
data$Clintonfav[data$polfavorability_2==4]=1

#Obama favorability: rating from very unfavorable to very favorable
data$Obamafav <-NA
data$Obamafav[data$polfavorability_3==1]=4
data$Obamafav[data$polfavorability_3==2]=3
data$Obamafav[data$polfavorability_3==3]=2
data$Obamafav[data$polfavorability_3==4]=1

#Paul Ryan favorability: rating from very unfavorable to very favorable
data$Ryanfav <-NA
data$Ryanfav[data$polfavorability_4==1]=4
data$Ryanfav[data$polfavorability_4==2]=3
data$Ryanfav[data$polfavorability_4==3]=2
data$Ryanfav[data$polfavorability_4==4]=1

#sex
data$sex<-NA
data$sex[data$Q110==1]=0
data$sex[data$Q110==2]=1

#Age
data$age<-(2016-as.numeric(data$Q116, na.rm=T)) #ignore warning

#Education
data$education<-data$hs

#Income
data$income<-data$Q114

#Code Agreeableness
data$Agre_2_rec<-(6-as.numeric(data$Q150_2)) # ignore warnings
data$Agre_4_rec<-(6-as.numeric(data$Q150_4))
data$Agre_6_rec<-(6-as.numeric(data$Q150_6))
data$Agre_8_rec<-(6-as.numeric(data$Q150_8))
data$Agre_10_rec<-(6-as.numeric(data$Q150_10))

#Create Agreeableness
data$Agre<-rowMeans(data.frame(data$Agre_2_rec, data$Agre_4_rec, data$Agre_6_rec, data$Agre_8_rec, data$Agre_10_rec, as.numeric(data$Q150_1), as.numeric(data$Q150_3), as.numeric(data$Q150_5), as.numeric(data$Q150_7), as.numeric(data$Q150_9)), na.rm=T)
#combine Agreeableness
Agreeable<-c(data$Agre, data$Agre)

#Create authoritarianism
data$auth_1[data$auth1==2]=1
data$auth_1[data$auth1==1]=0

data$auth_2[data$auth2==2]=0
data$auth_2[data$auth2==1]=1

data$auth_3[data$auth3==2]=1
data$auth_3[data$auth3==1]=0

data$auth_4[data$auth4==2]=1
data$auth_4[data$auth4==1]=0

#Create authoritarianism scale
data$authoritarianism<-rowMeans(data.frame(data$auth_1+data$auth_2+data$auth_3+data$auth_4), na.rm=T)

#combine Authoritarianism
Authoritarian<-c(data$authoritarianism, data$authoritarianism)
           
#create PID
data$partyidentity <- NA
data$partyidentity[data$pid2==1]=1
data$partyidentity[data$pid2==2]=2
data$partyidentity[data$pid4==2]=3
data$partyidentity[data$pid4==3| data$pid1>=3]=4
data$partyidentity[data$pid4==1]=5
data$partyidentity[data$pid3==2]=6
data$partyidentity[data$pid3==1]=7
#combine PID
PID<-c(data$partyidentity, data$partyidentity)


#create income
data$income01<-as.numeric(data$income) # ignore warning

#set NA to missing
data_trump <- data
save(data_trump, file="Study 2/data_trump.RData")


# Continue to create dataset.RData --------------------------------------------



#######################################
#Create Vote choice round 1
####################################### 

#vote candidate round
data$chooseA <- ifelse(data$Popchoice1==2,0,1)
data$chooseB <- ifelse(data$Popchoice1==1,0,1)
choose.1<-c(data$chooseA, data$chooseB)

#######################################
#Create Vote choice round 2
####################################### 
data$chooseA2[data$Q159==1]=1
data$chooseA2[data$Q159==2]=0

data$chooseB2[data$Q159==1]=0
data$chooseB2[data$Q159==2]=1

choose.2<-c(data$chooseA2, data$chooseB2)


#####################################
#Candidate evaluation round 1
#####################################

Feeling.1<-c(data$Pop1_feeling_1, data$Pop1_feeling_2)

#####################################
#Candidate evaluation round 2
#####################################
Feeling.2<-c(data$Pop2_feelings_1, data$Pop2_feelings_2)

#####################################
#
#Establishment: pro vs. anti
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#recode character to factor
data$Rd_1_A_Washington<-as.factor(data$Rd_1_A_Washington)

#0=pro-elite, 1=anti-elite
data$dum_Rd_1_A_Washington[data$Rd_1_A_Washington=="The House of Representatives is chock full of honest and hard-working people who care for ordinary Americans"]=0
data$dum_Rd_1_A_Washington[data$Rd_1_A_Washington=="The House of Representatives is chock full of Washington insiders who only care about protecting special interests."]=1

#####################################
#Round 1, candidate B
#####################################
#recode character to factor
data$Rd_1_B_Washington<-as.factor(data$Rd_1_B_Washington)

#0=pro-elite, 1=anti-elite
data$dum_Rd_1_B_Washington[data$Rd_1_B_Washington=="The House of Representatives is chock full of honest and hard-working people who care for ordinary Americans"]=0
data$dum_Rd_1_B_Washington[data$Rd_1_B_Washington=="The House of Representatives is chock full of Washington insiders who only care about protecting special interests."]=1

#Combine antiestablishment treatments
antiestablishment.1<-c(data$dum_Rd_1_A_Washington, data$dum_Rd_1_B_Washington)

#####################################
#Round 2, candidate A
#####################################
#recode character to factor
data$Rd_2_A_Washington<-as.factor(data$Rd_2_A_Washington)

data$dum_Rd_2_A_Washington<-NA
#0=pro-elite, 1=anti-elite
data$dum_Rd_2_A_Washington[data$Rd_2_A_Washington=="The House of Representatives is chock full of honest and hard-working people who care for ordinary Americans"]=0
data$dum_Rd_2_A_Washington[data$Rd_2_A_Washington=="The House of Representatives is chock full of Washington insiders who only care about protecting special interests."]=1

#####################################
#Round 2, candidate B
#####################################
#recode character to factor
data$Rd_2_B_Washington<-as.factor(data$Rd_2_B_Washington)

#0=pro-elite, 1=anti-elite
data$dum_Rd_2_B_Washington[data$Rd_2_B_Washington=="The House of Representatives is chock full of honest and hard-working people who care for ordinary Americans"]=0
data$dum_Rd_2_B_Washington[data$Rd_2_B_Washington=="The House of Representatives is chock full of Washington insiders who only care about protecting special interests."]=1

#Combine antiestablishment treatments
antiestablishment.2<-c(data$dum_Rd_2_A_Washington, data$dum_Rd_2_B_Washington)

#####################################
#
#Cooparation: cooperation vs. fight
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#recode character to factor
data$Rd_1_A_House<-as.factor(data$Rd_1_A_House)

#0=cooperation, 1=fight
data$dum_Rd_1_A_House[data$Rd_1_A_House=="I will cooperate with other Representatives to get my proposals accepted in the House"]=0
data$dum_Rd_1_A_House[data$Rd_1_A_House=="I will fight my opponents to get my proposals accepted in the House"]=1
table(data$dum_Rd_1_A_House)
#####################################
#Round 1, candidate B
#####################################
#recode character to factor
data$Rd_1_B_House<-as.factor(data$Rd_1_B_House)

#0=cooperation, 1=fight
data$dum_Rd_1_B_House[data$Rd_1_B_House=="I will cooperate with other Representatives to get my proposals accepted in the House"]=0
data$dum_Rd_1_B_House[data$Rd_1_B_House=="I will fight my opponents to get my proposals accepted in the House"]=1
table(data$dum_Rd_1_B_House)

#Combine Coopeartion treatments
cooperation.1<-c(data$dum_Rd_1_A_House, data$dum_Rd_1_B_House)
length(cooperation.1)

#####################################
#Round 2, candidate A
#####################################
#recode character to factor
data$Rd_2_A_House<-as.factor(data$Rd_2_A_House)

#0=cooperation, 1=fight
data$dum_Rd_2_A_House[data$Rd_2_A_House=="I will cooperate with other Representatives to get my proposals accepted in the House"]=0
data$dum_Rd_2_A_House[data$Rd_2_A_House=="I will fight my opponents to get my proposals accepted in the House"]=1
table(data$dum_Rd_2_A_House)
#####################################
#Round 2, candidate B
#####################################
#recode character to factor
data$Rd_2_B_House<-as.factor(data$Rd_2_B_House)

#0=cooperation, 1=fight
data$dum_Rd_2_B_House[data$Rd_2_B_House=="I will cooperate with other Representatives to get my proposals accepted in the House"]=0
data$dum_Rd_2_B_House[data$Rd_2_B_House=="I will fight my opponents to get my proposals accepted in the House"]=1
table(data$dum_Rd_2_B_House)

#Combine Coopeartion treatments
cooperation.2<-c(data$dum_Rd_2_A_House, data$dum_Rd_2_B_House)
length(cooperation.2)

#####################################
#
#Representation: mass vs. elite
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#recode character to factor
data$Rd_1_A_Representation<-as.factor(data$Rd_1_A_Representation)

#0=cooperation, 1=fight
data$dum_Rd_1_A_Representation[data$Rd_1_A_Representation=="I will do what is best for America even if the people disagree"]=0
data$dum_Rd_1_A_Representation[data$Rd_1_A_Representation=="I will do everything the American people want"]=1
table(data$dum_Rd_1_A_Representation)

#####################################
#Round 1, candidate B
#####################################
#recode character to factor
data$Rd_1_B_Representation<-as.factor(data$Rd_1_B_Representation)

#0=cooperation, 1=fight
data$dum_Rd_1_B_Representation[data$Rd_1_B_Representation=="I will do what is best for America even if the people disagree"]=0
data$dum_Rd_1_B_Representation[data$Rd_1_B_Representation=="I will do everything the American people want"]=1
table(data$dum_Rd_1_B_Representation)

#Combine Coopeartion treatments
representation.1<-c(data$dum_Rd_1_A_Representation, data$dum_Rd_1_B_Representation)
length(representation.1)

#####################################
#Round 2, candidate A
#####################################
#recode character to factor
class(data$Rd_2_A_Representation)
data$Rd_2_A_Representation<-as.factor(data$Rd_2_A_Representation)

#0=cooperation, 1=fight
data$dum_Rd_2_A_Representation[data$Rd_2_A_Representation=="I will do what is best for America even if the people disagree"]=0
data$dum_Rd_2_A_Representation[data$Rd_2_A_Representation=="I will do everything the American people want"]=1
table(data$dum_Rd_2_A_Representation)

#####################################
#Round 2, candidate B
#####################################
#recode character to factor
data$Rd_2_B_Representation<-as.factor(data$Rd_2_B_Representation)

#0=cooperation, 1=fight
data$dum_Rd_2_B_Representation[data$Rd_2_B_Representation=="I will do what is best for America even if the people disagree"]=0
data$dum_Rd_2_B_Representation[data$Rd_2_B_Representation=="I will do everything the American people want"]=1
table(data$dum_Rd_2_B_Representation)

#Combine Coopeartion treatments
data$Representation2<-cbind(data$dum_Rd_2_A_Representation, data$dum_Rd_2_B_Representation)
length(data$Representation2)
table(data$Representation2)

#Combine Coopeartion treatments
representation.2<-c(data$dum_Rd_2_A_Representation, data$dum_Rd_2_B_Representation)
length(representation.2)

#####################################
#
#Immigration
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#recode character to factor
data$Rd_1_A_Immigration<-as.factor(data$Rd_1_A_Immigration)

#categorical variable
data$dum_Rd_1_A_Immigration[data$Rd_1_A_Immigration=="Immigrants from countries that are torn apart by war or natural disaster should be welcomed in America."]=1
data$dum_Rd_1_A_Immigration[data$Rd_1_A_Immigration=="Immigration is good for our economy. Immigrants will take the jobs no one wants and bolster economic growth."]=2
data$dum_Rd_1_A_Immigration[data$Rd_1_A_Immigration=="Immigrants steal jobs from ordinary Americans. We need to protect our economy and stop immigration."]=3
data$dum_Rd_1_A_Immigration[data$Rd_1_A_Immigration=="America is for Americans. Immigrants are threatening our way of life."]=4
table(data$dum_Rd_1_A_Immigration)

#####################################
#Round 1, candidate B
#####################################
#recode character to factor
data$Rd_1_B_Immigration<-as.factor(data$Rd_1_B_Immigration)

#categorical variable
data$dum_Rd_1_B_Immigration[data$Rd_1_B_Immigration=="Immigrants from countries that are torn apart by war or natural disaster should be welcomed in America."]=1
data$dum_Rd_1_B_Immigration[data$Rd_1_B_Immigration=="Immigration is good for our economy. Immigrants will take the jobs no one wants and bolster economic growth."]=2
data$dum_Rd_1_B_Immigration[data$Rd_1_B_Immigration=="Immigrants steal jobs from ordinary Americans. We need to protect our economy and stop immigration."]=3
data$dum_Rd_1_B_Immigration[data$Rd_1_B_Immigration=="America is for Americans. Immigrants are threatening our way of life."]=4
table(data$dum_Rd_1_B_Immigration)

#Combine Immigration treatments
Immigration.1<-c(data$dum_Rd_1_A_Immigration, data$dum_Rd_1_B_Immigration)
table(Immigration.1)
length(Immigration.1)
#####################################
#Round 2, candidate A
#####################################
#recode character to factor
data$Rd_2_A_Immigration<-as.factor(data$Rd_2_A_Immigration)

#categorical variable
data$dum_Rd_2_A_Immigration[data$Rd_2_A_Immigration=="Immigrants from countries that are torn apart by war or natural disaster should be welcomed in America."]=1
data$dum_Rd_2_A_Immigration[data$Rd_2_A_Immigration=="Immigration is good for our economy. Immigrants will take the jobs no one wants and bolster economic growth."]=2
data$dum_Rd_2_A_Immigration[data$Rd_2_A_Immigration=="Immigrants steal jobs from ordinary Americans. We need to protect our economy and stop immigration."]=3
data$dum_Rd_2_A_Immigration[data$Rd_2_A_Immigration=="America is for Americans. Immigrants are threatening our way of life."]=4
table(data$dum_Rd_2_A_Immigration)

#####################################
#Round 2, candidate B
#####################################
#recode character to factor
data$Rd_2_B_Immigration<-as.factor(data$Rd_2_B_Immigration)

#categorical variable
data$dum_Rd_2_B_Immigration[data$Rd_2_B_Immigration=="Immigrants from countries that are torn apart by war or natural disaster should be welcomed in America."]=1
data$dum_Rd_2_B_Immigration[data$Rd_2_B_Immigration=="Immigration is good for our economy. Immigrants will take the jobs no one wants and bolster economic growth."]=2
data$dum_Rd_2_B_Immigration[data$Rd_2_B_Immigration=="Immigrants steal jobs from ordinary Americans. We need to protect our economy and stop immigration."]=3
data$dum_Rd_2_B_Immigration[data$Rd_2_B_Immigration=="America is for Americans. Immigrants are threatening our way of life."]=4
table(data$dum_Rd_2_B_Immigration)

#Combine Immigration treatments
Immigration.2<-c(data$dum_Rd_2_A_Immigration, data$dum_Rd_2_B_Immigration)
table(Immigration.2)
length(Immigration.2)

#####################################
#
#Taxation
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#remove the errors in the text and set to missing
#data$Rd_1_A_Taxation <- gsub("�???T", "", data$Rd_1_A_Taxation)
data$Rd_1_A_Taxation<-as.factor(data$Rd_1_A_Taxation)
unique.Rd_1_A_taxation <- unique(str_sub(data$Rd_1_A_Taxation,1,10))[-1]

#categorical variable
data$dum_Rd_1_A_Taxation <- ifelse(str_sub(data$Rd_1_A_Taxation,1,10)==unique.Rd_1_A_taxation[2],1,
                                   ifelse(str_sub(data$Rd_1_A_Taxation,1,10)==unique.Rd_1_A_taxation[3],2,
                                          ifelse(str_sub(data$Rd_1_A_Taxation,1,10)==unique.Rd_1_A_taxation[4],3,       
                                                 ifelse(str_sub(data$Rd_1_A_Taxation,1,10)==unique.Rd_1_A_taxation[5],4,NA))))
table(data$dum_Rd_1_A_Taxation)

#####################################
#Round 1, candidate B
#####################################


# unique.Rd_1_A_Taxation heeft dezelfde categorieen als Rd_1_B_Taxation, dus we hoeven geen nieuwe unieke waarden variabele te maken.
data$dum_Rd_1_B_Taxation <- ifelse(str_sub(data$Rd_1_B_Taxation,1,10)==unique.Rd_1_A_taxation[2],1,
                                   ifelse(str_sub(data$Rd_1_B_Taxation,1,10)==unique.Rd_1_A_taxation[3],2,
                                          ifelse(str_sub(data$Rd_1_B_Taxation,1,10)==unique.Rd_1_A_taxation[4],3,       
                                                 ifelse(str_sub(data$Rd_1_B_Taxation,1,10)==unique.Rd_1_A_taxation[5],4,NA))))
table(data$dum_Rd_1_B_Taxation)

#Combine Immigration treatments
Taxation.1<-c(data$dum_Rd_1_A_Taxation, data$dum_Rd_1_B_Taxation)

#####################################
#Round 2, candidate A
#####################################
data$dum_Rd_2_A_Taxation <- ifelse(str_sub(data$Rd_2_A_Taxation,1,10)==unique.Rd_1_A_taxation[2],1,
                                   ifelse(str_sub(data$Rd_2_A_Taxation,1,10)==unique.Rd_1_A_taxation[3],2,
                                          ifelse(str_sub(data$Rd_2_A_Taxation,1,10)==unique.Rd_1_A_taxation[4],3,       
                                                 ifelse(str_sub(data$Rd_2_A_Taxation,1,10)==unique.Rd_1_A_taxation[5],4,NA))))

table(data$dum_Rd_2_A_Taxation)

#####################################
#Round 2, candidate B
#####################################
data$dum_Rd_2_B_Taxation <- ifelse(str_sub(data$Rd_2_B_Taxation,1,10)==unique.Rd_1_A_taxation[2],1,
                                   ifelse(str_sub(data$Rd_2_B_Taxation,1,10)==unique.Rd_1_A_taxation[3],2,
                                          ifelse(str_sub(data$Rd_2_B_Taxation,1,10)==unique.Rd_1_A_taxation[4],3,       
                                                 ifelse(str_sub(data$Rd_2_B_Taxation,1,10)==unique.Rd_1_A_taxation[5],4,NA))))



table(data$dum_Rd_2_B_Taxation)

#Combine Immigration treatments
Taxation.2<-c(data$dum_Rd_2_A_Taxation, data$dum_Rd_2_B_Taxation)

#####################################
#
#Background
#
#####################################

#####################################
#Round 1, candidate A
#####################################
#recode character to factor
data$Rd_1_A_Background<-as.factor(data$Rd_1_A_Background)

#categorical variable
data$dum_Rd_1_A_Background[data$Rd_1_A_Background=="I have been a politician for most of my career."]=1
data$dum_Rd_1_A_Background[data$Rd_1_A_Background=="I worked as an economic advisor of the federal government before running for office"]=2
data$dum_Rd_1_A_Background[data$Rd_1_A_Background=="I worked as a management consultant before running for office."]=3
data$dum_Rd_1_A_Background[data$Rd_1_A_Background=="I worked as a social worker before running for office"]=4
table(data$dum_Rd_1_A_Background)

#####################################
#Round 1, candidate B
#####################################
#recode character to factor
data$Rd_1_B_Background<-as.factor(data$Rd_1_B_Background)

#categorical variable
data$dum_Rd_1_B_Background[data$Rd_1_B_Background=="I have been a politician for most of my career."]=1
data$dum_Rd_1_B_Background[data$Rd_1_B_Background=="I worked as an economic advisor of the federal government before running for office"]=2
data$dum_Rd_1_B_Background[data$Rd_1_B_Background=="I worked as a management consultant before running for office."]=3
data$dum_Rd_1_B_Background[data$Rd_1_B_Background=="I worked as a social worker before running for office"]=4
table(data$dum_Rd_1_B_Background)

#Aggregate immigration treatments
background.1<-c(data$dum_Rd_1_A_Background, data$dum_Rd_1_B_Background)
table(background.1)
length(background.1)
#####################################
#Round 2, candidate A
#####################################
#recode character to factor
data$Rd_2_A_Background<-as.factor(data$Rd_2_A_Background)

#categorical variable
data$dum_Rd_2_A_Background[data$Rd_2_A_Background=="I have been a politician for most of my career."]=1
data$dum_Rd_2_A_Background[data$Rd_2_A_Background=="I worked as an economic advisor of the federal government before running for office"]=2
data$dum_Rd_2_A_Background[data$Rd_2_A_Background=="I worked as a management consultant before running for office."]=3
data$dum_Rd_2_A_Background[data$Rd_2_A_Background=="I worked as a social worker before running for office"]=4
table(data$dum_Rd_2_A_Background)

#####################################
#Round 2, candidate B
#####################################
#recode character to factor
data$Rd_2_B_Background<-as.factor(data$Rd_2_B_Background)

#categorical variable
data$dum_Rd_2_B_Background[data$Rd_2_B_Background=="I have been a politician for most of my career."]=1
data$dum_Rd_2_B_Background[data$Rd_2_B_Background=="I worked as an economic advisor of the federal government before running for office"]=2
data$dum_Rd_2_B_Background[data$Rd_2_B_Background=="I worked as a management consultant before running for office."]=3
data$dum_Rd_2_B_Background[data$Rd_2_B_Background=="I worked as a social worker before running for office"]=4
table(data$dum_Rd_2_B_Background)

#Aggregate immigration treatments
background.2<-c(data$dum_Rd_2_A_Background, data$dum_Rd_2_B_Background)
table(background.2)
length(background.2)


###########################
#Cvariates
###########################

###########################
#sex
###########################
data$sex<-NA
data$sex[data$Q110==1]=0
data$sex[data$Q110==2]=1
sex <-c(data$sex, data$sex)

###########################
#Age
###########################
data$age<-(2016-as.numeric(data$Q116, na.rm=T))
age <-c(data$age, data$age)

############################
#education
###########################
data$education<-data$hs
education<-c(data$education, data$education)

#Income
data$income<-data$Q114
income<-c(data$income, data$income)


#######################################
#
#Transformations
#
#######################################

#create .data.frame with variables
data_long <- data.frame(rep(id,2), c(choose.1,choose.2), c(Feeling.1, Feeling.2), c(antiestablishment.1, antiestablishment.2), c(cooperation.1, cooperation.2), c(representation.1, representation.2), c(Immigration.1, Immigration.2), c(Taxation.1, Taxation.2), c(background.1, background.2), rep(Agreeable,2), rep(Authoritarian,2), rep(PID,2), rep(sex,2), rep(age,2), rep(education,2), rep(income,2))
colnames(data_long) <- c("id", "vote", "feeling", "anti", "cooperate", "represent", "immi", "tax", "background", "Agreeable", "Authoritarian", "PID", "sex", "age", "education", "income")
data_long$round <- c(rep(0,2420),rep(1,2420))
#set NA to missing
data_long.m <- data_long[-which(is.na(data_long$vote)),]

#creat dummy variables to plot interaction effects
data_long.m$immi2<- ifelse(data_long.m$immi==2,1,0)
data_long.m$immi3<- ifelse(data_long.m$immi==3,1,0)
data_long.m$immi4<- ifelse(data_long.m$immi==4,1,0)

#creat dummy variables to plot interaction effects
data_long.m$tax1<- ifelse(data_long.m$tax==1,1,0)
data_long.m$tax2<- ifelse(data_long.m$tax==2,1,0)
data_long.m$tax3<- ifelse(data_long.m$tax==3,1,0)
data_long.m$tax4<- ifelse(data_long.m$tax==4,1,0)

#creat dummy variables to plot interaction effects
data_long.m$edu_highschool<- ifelse(data_long.m$education==2,1,0)
data_long.m$edu_somecollege<- ifelse(data_long.m$education==3,1,0)
data_long.m$edu_2years<- ifelse(data_long.m$education==4,1,0)
data_long.m$edu_4years<- ifelse(data_long.m$education==5,1,0)
data_long.m$edu_professional<- ifelse(data_long.m$education==6,1,0)
data_long.m$edu_doctorate<- ifelse(data_long.m$education==7,1,0)

#save(data_long.m, file="dataset.RData")



save(data_long.m, file="Study 2/Study2_dataset.RData")


